package cn.com.headfree.recordlog.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.gta.edu.sdk.base.dao.impl.BaseDaoImpl;
import com.gta.edu.sdk.common.dto.Page;

import cn.com.headfree.entity.TRecordOptLog;
import cn.com.headfree.entity.TSysDictionaryInfo;
import cn.com.headfree.recordlog.dao.IRecordLogDao;

/**  
 * @Title  IRecordLogDaoImpl.java   
 * @Package cn.com.headfree.recordlog.dao.impl   
 * @Description 业务记录操作日志信息daoImpl
 * @author yangwang 
 * @date  2020年7月3日 下午3:44:57   
 */
@Repository("recordLogDao")
public class RecordLogDaoImpl extends BaseDaoImpl<TRecordOptLog> implements IRecordLogDao {
	
	/**
	 * 插入记录
	 * @param record
	 *  */
	@Override
	public void insert(TRecordOptLog record) {
		String sql = "insert into t_record_opt_log(id,record_id,opt_type,opt_user_name,opt_user_id,opt_time,opt_content,current_record_id,opt_status) values";
    	StringBuilder sb = new StringBuilder(sql);
		sb.append("(#{id,jdbcType=VARCHAR},")
		.append("#{record_id,jdbcType=VARCHAR},")
		.append("#{opt_type,jdbcType=VARCHAR},")
		.append("#{opt_user_name,jdbcType=VARCHAR},")
		.append("#{opt_user_id,jdbcType=VARCHAR},")
		.append("#{opt_time},")
		.append("#{opt_content,jdbcType=VARCHAR},")
		.append("#{current_record_id,jdbcType=VARCHAR},")
		.append("#{opt_status,jdbcType=INTEGER})");
		
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("id", record.getId());
        params.put("record_id", record.getRecordId());
        params.put("opt_type", record.getOptType());
        params.put("opt_user_name", record.getOptUserName());
        params.put("opt_user_id", record.getOptUserId());
        params.put("opt_time", record.getOptTime());
        params.put("opt_content", record.getOptContent());
		params.put("current_record_id", record.getCurrentRecordId());
		params.put("opt_status", record.getOptStatus());
        
        this.executeSql(sb.toString(), params);
	}
	
	/**
	 * 获取记录列表
	 * @param record
	 * @return List<TRecordOptLog>
	 *  */
	@Override
	public List<TRecordOptLog> getList(TRecordOptLog record){
		String sql = "select distinct id,record_id,opt_type,opt_user_name,opt_user_id,opt_time,opt_content";
    	StringBuilder sb = new StringBuilder(sql);
    	sb.append(" from t_record_opt_log")
    	.append(" where record_id=?")
    	.append(" order by opt_time desc");
    	
    	return this.findAllBySQL(TRecordOptLog.class, sb.toString(), null, false, new Object[] {record.getRecordId()});
	}
	
	/**
	 * 获取分页记录信息
	 * @param record
	 *  */
	@Override
	public void getPage(Page<TRecordOptLog> page,TRecordOptLog record) {
		String sql = "select distinct id,record_id,opt_type,opt_user_name,opt_user_id,opt_time,opt_content";
    	StringBuilder sb = new StringBuilder(sql);
    	sb.append(" from t_record_opt_log")
    	.append(" where record_id=?")
    	.append(" order by opt_time desc");
    	
    	this.findPageBySql(TRecordOptLog.class, sb.toString(), page, new Object[] {record.getRecordId()});
	}
	
	/**
	 * 获取字典列表
	 * @param value
	 * @return List<TSysDictionaryInfo>
	 *  */
	@Override
	public List<TSysDictionaryInfo> getDictionarys(String value){
		String sql = "select id,name,value from t_sys_dictionary_info ";
    	StringBuilder sb = new StringBuilder(sql);
    	sb.append(" where del_sign=0")
    	.append("  and p_id=(select id")
    	.append("  from t_sys_dictionary_info")
    	.append(" where del_sign=0")
    	.append(" and value=?)");
    	
    	return this.findAllBySQL(TSysDictionaryInfo.class, sb.toString(), null, false, new Object[] {value});
	}
	
}
